package vn.codespot.hms;

import vn.codespot.hms.slidingmenu.SlidingActivityHelper;
import vn.codespot.hms.slidingmenu.SlidingMenu;
import android.os.Bundle;
import android.app.Activity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;

public class AbstractActivity extends Activity {
    private SlidingActivityHelper mHelper;

    public void setMenu(SlidingActivityHelper helper) {
        mHelper = helper;
    }

    public void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mHelper.onPostCreate(savedInstanceState);
    }

    public View findViewById(int id) {
        View v = super.findViewById(id);
        if (v != null)
            return v;
        return mHelper.findViewById(id);
    }

    public void setContentView(int id) {
        setContentView(getLayoutInflater().inflate(id, null));
    }

    public void setContentView(View v) {
        setContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    }

    public void setContentView(View v, LayoutParams params) {
        super.setContentView(v, params);
        mHelper.registerAboveContentView(v, params);
    }

    public void setBehindContentView(int id) {
        setBehindContentView(getLayoutInflater().inflate(id, null));
    }

    public void setBehindContentView(View v) {
        setBehindContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    }

    public void setBehindContentView(View v, LayoutParams params) {
        mHelper.setBehindContentView(v, params);
    }

    public SlidingMenu getSlidingMenu() {
        return mHelper.getSlidingMenu();
    }

    public void toggle() {
        mHelper.toggle();
    }

    public void showAbove() {
        mHelper.showAbove();
    }

    public void showBehind() {
        mHelper.showBehind();
    }

    public void setSlidingActionBarEnabled(boolean b) {
        mHelper.setSlidingActionBarEnabled(b);
    }

    public void setBehindOffset(int i) {
        mHelper.getSlidingMenu().setBehindOffset(i);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        boolean b = mHelper.onKeyDown(keyCode, event);
        if (b)
            return b;
        return super.onKeyDown(keyCode, event);
    }
}
